using NUnit.Framework;

namespace ValidationFramework.PropertyValidationManagerTests
{
    [TestFixture]
    public class InheritanceTests
    {

        public class BaseClass
        {

            [RequiredStringRule]
            public string Property1
            {
                get;
                set;
            }
        }

        public class InheritedClass : BaseClass
        {

            [RequiredStringRule]
            public string Property2
            {
                get;
                set;
            }
        }

        [Test]
        public void InstanceValidate()
        {
            var baseClass = new BaseClass();
            var baseClassPropertyValidationManager = ValidationManagerFactory.GetPropertyValidationManager(baseClass);
            baseClassPropertyValidationManager.ValidateAll();
            Assert.AreEqual(1, baseClassPropertyValidationManager.ValidatorResultsInError.Count);

            var inheritedClass = new InheritedClass();
            var inheritedClassPropertyValidationManager = ValidationManagerFactory.GetPropertyValidationManager(inheritedClass);
            inheritedClassPropertyValidationManager.ValidateAll();
            Assert.AreEqual(2, inheritedClassPropertyValidationManager.ValidatorResultsInError.Count);
        }


        [Test]
        public void StaticValidate()
        {
            var baseClass = new BaseClass();
            var baseClassValidationErrors = PropertyValidationManager.ValidateAll(baseClass, null, null);
            Assert.AreEqual(1, baseClassValidationErrors.Count);

            var inheritedClass = new InheritedClass();
            var inheritedClassValidationErrors = PropertyValidationManager.ValidateAll(inheritedClass, null, null);
            Assert.AreEqual(2, inheritedClassValidationErrors.Count);
        }
    }
}
